<template>
  <div class="main">
    <div v-if="height < 600" class="menu_show">
      <!-- 员工信息 -->
      <div class="employee_info">
        <div class="employee_name">{{ user }}</div>
        <div class="employee_temperature">
          <span>{{ temperature }}℃</span>
          <span>{{ weather }}</span>
        </div>
      </div>
      <!-- 菜单 -->
      <div class="menu" v-for="menu in menuList">
        <div class="title" v-if="menu.title">
          {{ menu.title }}
        </div>
        <div class="content " :class="{ 'border': menu.border }">
          <div class="item" v-for="item in menu.list">
            <i class="iconfont custom_icon" :class="item.icon"></i>
            {{ item.title }}
          </div>
        </div>
        <div class="content">
          <div class="item" v-for="item in menu.list2">
            <i class="iconfont custom_icon" :class="item.icon"></i>
            {{ item.title }}
          </div>
        </div>
      </div>
    </div>
    <div v-else class="menu_done">
      <div class="menu_dom_item">
        <i class="iconfont icon-naozhong"></i>
        <i class="iconfont icon-chucha"></i>
        <i class="iconfont icon-jiabanshenqing"></i>
        <i class="iconfont icon-gongwenbao1"></i>
      </div>
      <div>
        <div>
          <van-icon name="arrow-down" />
        </div>
      </div>
    </div>
    <!-- 浮动面板 -->
    <van-floating-panel v-model:height="height" :anchors="anchors" @height-change="heightChange">
      <floatingPanel />
    </van-floating-panel>

    <van-tabbar v-model="active">
      <van-tabbar-item icon="home-o">消息</van-tabbar-item>
      <van-tabbar-item icon="search">日程</van-tabbar-item>
      <van-tabbar-item icon="friends-o">通讯录</van-tabbar-item>
      <van-tabbar-item icon="setting-o">我的</van-tabbar-item>
    </van-tabbar>
  </div>

</template>

<script setup>
import { nextTick, ref } from 'vue'
import floatingPanel from './floatingPanel.vue'
let active = ref(-1)
const anchors = [
  120,
  Math.round(0.82 * window.innerHeight),
  Math.round(0.95 * window.innerHeight),
];
const height = ref(anchors[1]);
const menuHeight = Math.round(0.05 * window.innerHeight) + 'px'
const menuList = [
  {
    title: null,
    list: [
      { title: '请假', icon: 'icon-naozhong' },
      { title: '出差', icon: 'icon-chucha' },
      { title: '加班', icon: 'icon-jiabanshenqing' },
      { title: '出差', icon: 'icon-gongwenbao1' }
    ],
    border: true
  },
  {
    title: '自助服务',
    list: [
    ],
    border: true
  },
  {
    title: '我的假勤',
    list: [
      { title: '补签', icon: 'icon-zhiwen' },
    ],
    border: true
  },
  {
    title: '我的招聘',
    list: [
      { title: '筛选', icon: 'icon-a1' },
      { title: '面试', icon: 'icon-ball-camera' },
      { title: '审批', icon: 'icon-shenpi' },
    ],
    list2: [
      { title: '转正申请', icon: 'icon-zhuanzheng-' },
      { title: '调动申请', icon: 'icon-yonghu_tiaodongshenqing' },
      { title: '离职申请', icon: 'icon-hrstaffdimission' },
      { title: '调薪申请', icon: 'icon-tiaoxinguanli' },
      { title: '我的工资', icon: 'icon-richeng' },
      { title: '我的申请', icon: 'icon-shenqing' },
      { title: '考勤', icon: 'icon-kaoqin' },
      { title: '考勤月报', icon: 'icon-yuebao' },
      { title: '我的排班', icon: 'icon-paibanoff' },
      { title: '调班', icon: 'icon-tiaoketiaoban' },
      { title: '考勤日历', icon: 'icon-richeng' },
      { title: '团队调班', icon: 'icon-tiaobanshenqing' },
      { title: '日程', icon: 'icon-richeng_schedule' },
      { title: '动态', icon: 'icon-pengyouquan' },
      { title: '我的待办', icon: 'icon-daiban' },
      { title: '抄送我的', icon: 'icon-chaosongwode' },
      { title: '日程', icon: 'icon-richeng_schedule' },
      { title: '请假', icon: 'icon-shenqing' },
      { title: '出差', icon: 'icon-chucha' },
      { title: '加班', icon: 'icon-jiabanshenqing' },
      { title: '公出', icon: 'icon-gongwenbao1' },
      { title: '我的档案', icon: 'icon-wp-da' },
    ],
    border: true
  },
  {
    title: '假勤管理',
    list: [
      { title: '考勤查询', icon: 'icon-paibanoff' },
    ],
    border: false
  },
]

const user = ref('XXX')
const temperature = ref(9)
const weather = ref('阴')

const createDom = ({ height }) => {
  nextTick(() => {
    const dom = document.querySelector('.van-floating-panel__header')
    dom.innerHTML = ''
    if (height > 600) return
    const div = document.createElement('div')
    if (height === 120) {
      div.innerHTML = `<i class="iconfont icon-xiangshangshouqi"></i>`
    } else {
      div.textContent = '下拉查看菜单'
    }
    div.style.textAlign = 'center'
    div.style.color = '#888'
    div.style.fontSize = '12px'
    dom.appendChild(div)
  })
}

createDom({})

const heightChange = height => {
  createDom(height)
}
</script>

<style lang="scss" scoped>
.main {
  padding: 0 20px 200px;
  background: #000;

  :deep(.van-floating-panel__header-bar) {
    display: none;
  }

  .custom_icon {
    font-size: 40px;
  }

  .menu_show,
  .menu_done {
    color: #fff;

    .employee_name {
      text-indent: 2em;
      font-size: 18px;
      font-weight: 700;
      padding: 5px 0;
    }

    .employee_temperature {
      font-size: 14px;

      span {
        margin-right: 15px;
      }
    }

    .title {
      font-size: 16px;
      font-weight: 700;
      padding: 16px 0;
    }

    .content {
      display: flex;
      align-items: flex-start;
      flex-wrap: wrap;

      &.border {
        border-bottom: 2px solid #fff;
      }
    }

    .item {
      width: 25%;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 10px 0;
      font-size: 14px;

      :deep(.van-icon) {
        font-size: 40px;
      }
    }
  }

  .menu_done {
    display: flex;
    justify-content: space-between;
    height: v-bind(menuHeight);
    align-items: center;

    .menu_dom_item {
      display: flex;

      i {
        font-size: 22px;
        margin-right: 10px;
      }
    }

    :deep(.van-icon) {
      font-size: 20px;
    }
  }

  :deep(.van-tabbar) {
    z-index: 999;
  }

}
</style>
